<!DOCTYPE html>
<html>
<body>

<?php

$uname=($_POST["username"]);
$pwd=($_POST["password"]);

/* echo $uname; */

$query_str="SELECT * FROM users where username='{$uname}' and password=password('{$pwd}');";

/* echo "<br> {$query_str} <br>";*/

$mysqli = new mysqli("127.0.0.1", "root", "20155222", "lzj");

/* check connection */
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}


/* Select queries return a resultset */
if ($result = $mysqli->query($query_str)) {
	$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
	if ($result->num_rows > 0 ){
		setcookie("userid",current($row));
		setcookie("username",$uname);
		SetCookie("password",$pwd);

		echo "<br> Wellcome login Mr/Mrs:{$uname} <br> ";
		header("Location:http://127.0.0.1:5222/tieba.html");
	} else {
		echo "<br> login failed!!!! {$uname}<br> " ;
	}

    /* free result set */
    $result->close();
}


$mysqli->close();

?>

</body>
</html>
